﻿Imports Sistema_InformacionNaviera.BC
Imports Sistema_InformacionNaviera.BE
Imports Sistema_InformacionNavier.UTIL


Public Class GestionarDesglose

    'Inherits System.Web.UI.Page
    Inherits PaginaBase

    Dim mOk As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Dim iKvje As Integer
            Dim iKbli As Integer

            iKvje = Session("CodigVje")
            iKbli = Session("CodigBL")

            BuscarDatosBlImpo(iKvje, iKbli)
            CrearTablaTemporaBLHijos()
            CargarDatosBLDesglose()
            CalcularTotales()
            CalcularCantHijos()

        End If

        If My.Request.Params("__EVENTTARGET") = "MiFuncionPaquetes" Then

            If Session("BSSCodigoEntidadCON") = Nothing Then
                txtCodConsig.Text = String.Empty
            Else
                txtCodConsig.Text = Session("BSSCodigoEntidadCON")
                txtDesConsig.Text = Session("BSSNombreEntidadCON")

            End If

        End If


        If My.Request.Params("__EVENTTARGET") = "MiFuncionContenedor" Then

            If Session("BLCONT_Prefijo") = Nothing Then
                txtContenedor.Text = String.Empty
            Else
                txtContenedor.Text = Session("BLCONT_Cadena")
                txtPesoBruto.Text = Session("BLCONT_PesoBruto")


            End If

        End If

    End Sub

#Region "Tab: Bl Desglose - Obtener"

    Public Sub CargarDatosBLDesglose()
        Try

            'Dim objDesg As List(Of DesgloseBE)
            Dim objBLDesgloseBE As New DesgloseBE
            Dim objBLDesgloseBC As New DesgloseBC
            Dim bExito As Boolean = False
            Dim sMensaje As String = String.Empty
            Dim dt As DataTable = Nothing

            objBLDesgloseBE.KBle = Session("CodigBL")
            objBLDesgloseBE.Kvje = Session("CodigVje")

            objBLDesgloseBC.ObtenerDesgloseDetalle(objBLDesgloseBE, dt, bExito, sMensaje)

            If dt.Rows.Count > 0 Then
                If bExito Then

                    Me.dgDesgloseDeta.DataSource = dt
                    Me.dgDesgloseDeta.DataBind()
                    Session("tbTempBLHijos") = dt

                End If
            End If
           

        Catch ex As Exception
            ex.Message.ToString()
        End Try
    End Sub

#End Region

#Region "Tab: Bl Hijos"

    Public Sub CrearTablaTemporaBLHijos()
        Dim dt As New DataTable
        dt.Columns.Add("iBLHijoID")
        dt.Columns.Add("sBLHijoCodigo")
        dt.Columns.Add("sBLHijoConsig")
        dt.Columns.Add("sBLHijoCont")
        dt.Columns.Add("dBLHijoPeso")
        dt.Columns.Add("sBLHijoObs")
        dt.Columns.Add("sBLHijoEstado")
        Session("tbTempBLHijos") = dt
    End Sub



    Protected Sub btnAgregar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAgregar.Click

        Try
            Dim drItem As DataRow
            Dim i As Integer = 0
            Dim dt As New DataTable
            Dim iValidacion As Integer = 0
            Dim iValidacionCons As Integer = 0

            dt = Session("tbTempBLHijos")

            '-------------------------------------------------------------------------------------
            If txtNHijo.Text = String.Empty Then
                MsgBox("Ingrese el BL Hijo.", True, String.Empty)
                Exit Sub
            ElseIf txtCodConsig.Text.Trim = "" Then
                MsgBox("Ingrese el consignatario.", True, String.Empty)
                Exit Sub
            ElseIf txtPeso.Text = "" Then
                MsgBox("Ingrese el peso.", True, String.Empty)
                Exit Sub
            ElseIf txtObs.Text = String.Empty Then
                MsgBox("Ingrese la observación.", True, String.Empty)
                Exit Sub
            End If


            '-------------------------------------------------------------------------------------
            'agrega datos a tabla temporal 
            '------------------------------------------------------------------------
            If dt.Rows.Count > 0 Then

                'Para validar si hay registros repetidos
                Do While i < dt.Rows.Count
                    drItem = dt.Rows(i)


                    '------------------------------------------------
                    'Validacion de suma contenedores
                    '------------------------------------------------
                    Dim sPrefijo As String = Mid(txtContenedor.Text, 1, InStr(txtContenedor.Text, "-") - 1)
                    Dim sNUmero As String = Mid(txtContenedor.Text, InStr(txtContenedor.Text, "-"), Len(txtContenedor.Text))
                    Dim sTotalPesoBruto As Double
                    Dim dtCont As DataTable

                    dtCont = dt

                    dtCont = SelectDataTable(dt, " sBLHijoCont ='" & Trim(txtContenedor.Text) & "'  AND sBLHijoEstado <> '2' ", "") 'diferente de eliminados , con filtro en el contenedor

                    Do While i < dtCont.Rows.Count
                        drItem = dtCont.Rows(i)
                        sTotalPesoBruto = sTotalPesoBruto + CType(dtCont.Rows(i).Item("dBLHijoPeso"), Double)
                        i = i + 1
                    Loop

                    If sTotalPesoBruto + Val(txtPeso.Text) > Val(txtPesoBruto.Text) Then
                        MsgBox("ERROR: La Suma de Peso de los BL hijos deben ser menor al Peso de Contenedor .", True, String.Empty)
                        Exit Sub
                    End If


                    '------------------------------------------------
                    'Validacion de Codigo BL Hijo
                    '------------------------------------------------

                    If (txtNHijo.Text = drItem.Item(1).ToString) Then
                        If Session("Tipo_BLHijoEditar") = 1 Then ' Modificar
                            If Not dt.Rows(i).Item("sBLHijoEstado") = "2" Then '2= eliminados
                                iValidacion = iValidacion + 1

                            End If
                        Else
                            iValidacion = iValidacion + 1
                        End If
                    End If

                    '------------------------------------------------
                    'Validacion de Consignatario
                    '------------------------------------------------

                    If (txtCodConsig.Text = drItem.Item(2).ToString) Then
                        iValidacionCons = iValidacionCons + 1
                    End If

                    i = i + 1
                Loop

                '--------------------------------------------------------------------------------------------------------------

                If Session("ActivarModificacion") = 1 Then ' SI SE MODIFICA
                    ActualizarDatos_BlHijo()
                    Exit Sub
                End If

                If iValidacionCons <> 0 Then
                    MsgBox("ERROR: Ya se ingreso el consignatario " & txtContenedor.Text, True, String.Empty)
                    Exit Sub
                End If

                If iValidacion = 0 Then
                    Dim dRow As DataRow = dt.NewRow
                    dRow("iBLHijoID") = Date.Now.Day & Date.Now.Hour & Date.Now.Minute & Date.Now.Second
                    dRow("sBLHijoCodigo") = Me.txtNHijo.Text
                    dRow("sBLHijoConsig") = Me.txtCodConsig.Text
                    dRow("sBLHijoCont") = Me.txtContenedor.Text
                    dRow("dBLHijoPeso") = Me.txtPeso.Text
                    dRow("sBLHijoObs") = Me.txtObs.Text

                    '-------------------------------------------------------
                    'sBLHijoEstado - bl hijos
                    '0 - registro nuevo
                    '1 - registro modificado
                    '2 - eliminado
                    '-------------------------------------------------------


                    If Session("Tipo_BLHijoEditar") = 1 Then ' Modificar
                        dRow("sBLHijoEstado") = "1" 'Registro por modificar
                    Else
                        dRow("sBLHijoEstado") = "N" 'Registro Nuevo
                    End If

                    dt.Rows.Add(dRow)
                    Session("tbTempBLHijos") = dt
                    Me.dgDesgloseDeta.DataSource = SelectDataTable(dt, "sBLHijoEstado <> '2'", "") 'diferente de eliminados
                    Me.dgDesgloseDeta.DataBind()
                    CalcularTotales()
                    CalcularCantHijos()
                    LimpiarDatosBLHijos_Agregar()
                    Exit Sub
                Else
                    MsgBox("ERROR: Ya se ingreso el Nº de BL Hijo.", True, String.Empty)
                    Exit Sub
                End If

            Else

                If Val(txtPeso.Text) > Val(txtPesoBruto.Text) Then
                    MsgBox("El peso del BL hijo debe ser menor o igual al peso del contendor.", True, String.Empty)
                    Exit Sub
                End If

                Dim dRow As DataRow = dt.NewRow
                dRow("iBLHijoID") = Date.Now.Day & Date.Now.Hour & Date.Now.Minute & Date.Now.Second
                dRow("sBLHijoCodigo") = Me.txtNHijo.Text
                dRow("sBLHijoConsig") = Me.txtCodConsig.Text
                dRow("sBLHijoCont") = Me.txtContenedor.Text
                dRow("dBLHijoPeso") = Me.txtPeso.Text
                dRow("sBLHijoObs") = Me.txtObs.Text

                If Session("TipoTransaccionBLImpo") = 1 Then ' Modificar
                    dRow("sBLHijoEstado") = "1" 'Registro por modificar
                Else
                    dRow("sBLHijoEstado") = "N" 'Registro Nuevo
                End If


                dt.Rows.Add(dRow)
                Session("tbTempBLHijos") = dt
                Me.dgDesgloseDeta.DataSource = SelectDataTable(dt, "sBLHijoEstado <> '2'", "") 'diferente de eliminados
                Me.dgDesgloseDeta.DataBind()
                CalcularTotales()
                CalcularCantHijos()
                LimpiarDatosBLHijos_Agregar()
                End If


            Session("ActivarModificacion") = 0 ' termina la modificacion 





        Catch ex As Exception
            ex.Message.ToString()
        End Try

    End Sub


    Public Sub CalcularTotales()

        Dim drItem As DataRow
        Dim i As Integer = 0
        Dim dt As DataTable
        dt = Session("tbTempBLHijos")
        Dim sTotalPesoBruto As Double = 0
        Dim sTotalPesoNeto As Double = 0
        Dim sTotalTara As Double = 0
        Dim sTotalVolumen As Double = 0

        dt = SelectDataTable(dt, "sBLHijoEstado <> '2'", "") 'diferente de eliminado

        Do While i < dt.Rows.Count
            drItem = dt.Rows(i)
            sTotalPesoBruto = sTotalPesoBruto + CType(dt.Rows(i).Item("dBLHijoPeso"), Double)
            i = i + 1
        Loop


        'Calcular camtidades 
        lblTotalPesoBruto.Text = sTotalPesoBruto
    End Sub


    Public Sub CalcularCantHijos()

        Dim drItem As DataRow
        Dim i As Integer = 0
        Dim dt As DataTable
        dt = Session("tbTempBLHijos")
        Dim sTotalPesoBruto As Double = 0
        Dim sTotalPesoNeto As Double = 0
        Dim sTotalTara As Double = 0
        Dim sTotalVolumen As Double = 0

        dt = SelectDataTable(dt, "sBLHijoEstado <> '2'", "") 'diferente de eliminado

        Do While i < dt.Rows.Count
            drItem = dt.Rows(i)
            i = i + 1
        Loop


        'Calcular camtidades 
        lblTotalBLHijos.Text = i
    End Sub


    Function SelectDataTable(ByVal dt As DataTable, ByVal filter As String, ByVal sort As String) As DataTable

        Dim rows As DataRow()
        Dim dtNew As DataTable
        dtNew = dt.Clone()
        rows = dt.Select(filter, sort)
        For Each dr As DataRow In rows
            dtNew.ImportRow(dr)
        Next
        Return dtNew

    End Function

    Public Sub ActualizarDatos_BlHijo()

        Try
            Dim i As Integer = 0
            Dim dt As New DataTable
            dt = Session("tbTempBLHijos")
            btnCancelar.Enabled = True


            If dt.Rows.Count > 0 Then

                Do While i < dt.Rows.Count

                    If dt.Rows(i).Item("sBLHijoCodigo").ToString = CType(txtNHijo.Text.Trim, String) Then
                        dt.Rows(i).Item("sBLHijoCodigo") = Me.txtNHijo.Text
                        dt.Rows(i).Item("sBLHijoConsig") = Me.txtCodConsig.Text
                        dt.Rows(i).Item("sBLHijoCont") = Me.txtContenedor.Text
                        dt.Rows(i).Item("dBLHijoPeso") = Me.txtPeso.Text
                        dt.Rows(i).Item("sBLHijoObs") = Me.txtObs.Text
                        dt.Rows(i).Item("sBLHijoEstado") = "1" ' 1= actualizar
                        dgDesgloseDeta.DataSource = dt
                        dgDesgloseDeta.DataBind()
                        CalcularTotales()
                    End If
                    i = i + 1
                Loop
            End If

            Session("ActivarModificacion") = 0 ' termina la actualizar datos 
            btnCancelar.Visible = False
            LimpiarDatosBLHijos_Agregar()
            txtNHijo.Enabled = True

        Catch ex As Exception
            ex.Message.ToString()
        End Try

    End Sub

    Public Sub LimpiarDatosBLHijos()
        Me.txtIDBLHijo.Text = String.Empty
        Me.txtNHijo.Text = String.Empty
        Me.txtCodConsig.Text = String.Empty
        Me.txtDesConsig.Text = String.Empty
        Me.txtContenedor.Text = String.Empty
        Me.txtPeso.Text = String.Empty
        Me.txtObs.Text = String.Empty
        txtPesoBruto.Text = String.Empty

    End Sub

    Public Sub LimpiarDatosBLHijos_Agregar()
        Me.txtIDBLHijo.Text = String.Empty
        Me.txtNHijo.Text = String.Empty
        Me.txtCodConsig.Text = String.Empty
        Me.txtDesConsig.Text = String.Empty
        Me.txtPeso.Text = String.Empty
        Me.txtObs.Text = String.Empty
    End Sub

    Private Sub dgdgDesgloseDeta_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles dgDesgloseDeta.RowCommand

        Dim intCodigo As String = e.CommandArgument

        Select Case e.CommandName

            Case "Eliminar"

                'If Session("Tipo_BLHijoEditar") = 1 Then ' Modificar
                Eliminar_OpcionModificar(intCodigo)
                'Else
                '    Eliminar_OpcionNuevo(intCodigo)
                'End If

                CalcularTotales()

            Case "Editar"

                Dim dt As New DataTable
                Dim dtSel As New DataTable
                dt = Session("tbTempBLHijos")
                dtSel = SelectDataTable(dt, "iBLHijoID = " & intCodigo, "iBLHijoID DESC")
                btnCancelar.Visible = True
                txtNHijo.Enabled = False

                Me.txtIDBLHijo.Text = dtSel.Rows(0).Item("iBLHijoID")
                Me.txtNHijo.Text = dtSel.Rows(0).Item("sBLHijoCodigo").ToString
                Me.txtCodConsig.Text = dtSel.Rows(0).Item("sBLHijoConsig").ToString
                Me.txtContenedor.Text = dtSel.Rows(0).Item("sBLHijoCont").ToString
                Me.txtPeso.Text = dtSel.Rows(0).Item("dBLHijoPeso")
                Me.txtObs.Text = dtSel.Rows(0).Item("sBLHijoObs").ToString
                Session("ActivarModificacion") = 1

        End Select

    End Sub

    Private Sub Eliminar_OpcionModificar(ByVal intCodigo As String)


        Dim i As Integer = 0
        Dim rwEliminar As String
        Dim dt As New DataTable
        dt = Session("tbTempBLHijos")

        If dt.Rows.Count > 0 Then

            Do While i < dt.Rows.Count
                rwEliminar = dt.Rows(i).Item("iBLHijoID").ToString

                If rwEliminar = CType(intCodigo, String) Then

                    If CType(dt.Rows(i).Item("sBLHijoEstado"), String) = "N" Then ' si es nuevo se elimina definitivamnete

                        If MsgBox("Esta seguro de eliminar el registro?", vbYesNo, Me.Title) = MsgBoxResult.Yes Then
                            Me.dgDesgloseDeta.Rows(i).Visible = False
                            dt.Rows.Remove(dt.Rows(i))
                            Me.dgDesgloseDeta.DataSource = SelectDataTable(dt, "sBLHijoEstado <> '2'", "") ' diferente de eliminados = 2
                            Me.dgDesgloseDeta.DataBind()

                        End If

                    Else
                        If MsgBox("Esta seguro de eliminar el registro?", vbYesNo, Me.Title) = MsgBoxResult.Yes Then
                            dt.Rows(i).Item("sBLHijoEstado") = "2" 'Eliminacion 
                            Me.dgDesgloseDeta.Rows(i).Visible = False
                            Me.dgDesgloseDeta.DataSource = SelectDataTable(dt, "sBLHijoEstado <> '2'", "")
                            Me.dgDesgloseDeta.DataBind()

                        End If

                    End If

                End If

                i = i + 1
            Loop

            CalcularTotales()
            CalcularCantHijos()
        End If

    End Sub

    Private Sub Eliminar_OpcionNuevo(ByVal intCodigo As String)

        Dim i As Integer = 0
        Dim rwEliminar As String
        Dim dt As New DataTable
        dt = Session("tbTempBLHijos")

        If dt.Rows.Count > 0 Then

            Do While i < dt.Rows.Count
                rwEliminar = dt.Rows(i).Item("iBLHijoID").ToString

                If rwEliminar = CType(intCodigo, String) Then
                    If MsgBox("Esta seguro de eliminar el registro?", vbYesNo, Me.Title) = MsgBoxResult.Yes Then
                        dgDesgloseDeta.Rows(i).Visible = False
                        dt.Rows.Remove(dt.Rows(i))
                    End If

                End If

                i = i + 1
            Loop

        End If

        dgDesgloseDeta.DataSource = dt
        dgDesgloseDeta.DataBind()
        'ActualizarTarifa()
        CalcularTotales()

    End Sub


    Protected Sub btnLimpiar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLimpiar.Click
        LimpiarDatosBLHijos()
    End Sub

    Protected Sub btnCancelar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCancelar.Click
        LimpiarDatosBLHijos()
        btnCancelar.Visible = False
        txtNHijo.Enabled = True

        Session("ActivarModificacion") = 0

    End Sub



#End Region




    Public Sub BuscarDatosBlImpo(ByVal iViaje As Integer, ByVal iKbli As Integer)

        Try

            Dim objBlImpoBE As New BillOfLadingImpoBE
            Dim ImpoDesgloseBE As BillOfLadingImpoBE
            Dim objUtil As New Funciones
            Dim objBlImpoBC As New BillOfLadingImpoBC
            objBlImpoBE.KVJE = iViaje
            objBlImpoBE.KBLM = iKbli

            ImpoDesgloseBE = objBlImpoBC.ListarBlImpoDesglose(objBlImpoBE)
            If Not ImpoDesgloseBE Is Nothing Then
                lblNaveViaje.Text = ImpoDesgloseBE.desKVJE
                lblConsignatario.Text = ImpoDesgloseBE.desc_cod_cons
                lblBLMaster.Text = ImpoDesgloseBE.Nume
                lblTotalPeso.Text = ImpoDesgloseBE.Bec_Peso
                lblCantidadCntdres.Text = ImpoDesgloseBE.CantContenedores
                'lblRecepBL.Text = ImpoDesgloseBE.FecRevision
                lblEstado.Text = ImpoDesgloseBE.EstadoDes




            Else
                MsgBox("No se pudo cargar la información.", vbInformation, "Error")
            End If

        Catch ex As Exception
            ex.Message.ToString()
        End Try

    End Sub


    Protected Sub btnGrabar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnGrabar.Click
        Try

            Dim sUsuario As String = Session("idIusuario")
            Dim objDesgloseBE As DesgloseBE
            objDesgloseBE = New DesgloseBE
            objDesgloseBE.Usu = sUsuario

            'If Session("TipoTransaccionBLImpoDesglose") = 1 Then ' Modificar
            '    Modificar()
            'Else
            Nuevo()
            'End If

        Catch ex As Exception
            ex.Message.ToString()
        End Try
    End Sub



    Public Sub Nuevo()

        Try

            '--------------------------------------------------------------------------------------------------------
            ' Validacion del detalle
            '--------------------------------------------------------------------------------------------------------

            Dim dtBlHijo As New DataTable
            Dim TOPE As String = String.Empty

            dtBlHijo = Session("tbTempBLHijos")
          
            If dtBlHijo.Rows.Count = 0 Then
                MsgBox("ERROR: Debe ingresar los BL Hijos.", True, String.Empty)
                Exit Sub
            End If

            '--------------------------------------------------------------------------------------------------------
            ' Ingresar Desglose
            '--------------------------------------------------------------------------------------------------------

            Dim objBLDesgloseBE As DesgloseBE = Nothing
            Dim objBLDesgloseBC As DesgloseBC
            Dim bExito As Boolean = False
            Dim sMensaje As String = String.Empty
            Dim sUsuario As String = Session("idIusuario")


            Dim KVJE As Integer = Session("CodigVje")
            Dim KBLM As Integer = Session("CodigBL") ' correlativo de importacion

            'If Session("TipoTransaccionBLImpoDesglose") = 1 Then
            '    TOPE = "M" ' 
            'Else
            '    TOPE = "N" ' Tipo de Ingeso = Nuevo
            'End If

            'Dim sTipo As String = "I"
            Dim NumeBL As String = lblBLMaster.Text.Trim

            '------------------------------------------------
            ' si se va a modificar
            '------------------------------------------------
            'If Session("TipoTransaccionBLImpoDesglose") = 1 Then

            'objBLDesgloseBE.KBle = Session("CodigVje")
            'objBLDesgloseBE.Kvje = Session("CodigBL")

            'End If
            '------------------------------------------------

            objBLDesgloseBE = New DesgloseBE
            objBLDesgloseBE.Kvje = KVJE
            objBLDesgloseBE.KBle = KBLM
            objBLDesgloseBE.Nume = lblBLMaster.Text
            objBLDesgloseBE.Usu = Session("idIusuario")

            '------------------------------------------------
            '------------------------------------------------
            Dim i As Integer
            Dim drItem As DataRow

            If dtBlHijo.Rows.Count > 0 Then
                Do While i < dtBlHijo.Rows.Count
                    drItem = dtBlHijo.Rows(i)

                    Dim V_KBld As String = CType(drItem.Item("iBLHijoID").ToString, String)
                    Dim V_BLHijo As String = CType(drItem.Item("sBLHijoCodigo").ToString, String)
                    Dim V_Consig As String = CType(drItem.Item("sBLHijoConsig").ToString, String)
                    Dim V_Conten As String = CType(drItem.Item("sBLHijoCont").ToString, String)
                    Dim V_Peso As Double = CType(drItem.Item("dBLHijoPeso").ToString, Double)
                    Dim V_Obse As String = CType(drItem.Item("sBLHijoObs").ToString, String)
                    Dim V_Estado As String = CType(drItem.Item("sBLHijoEstado").ToString, String)


                    If V_Estado = "1" Then ' si se ha modificado un registro
                        TOPE = "M"
                    ElseIf V_Estado = "2" Then
                        TOPE = "M"
                        objBLDesgloseBE.Estado = 2
                    ElseIf V_Estado = "N" Then
                        TOPE = "N" ' Tipo de Ingeso = Nuevo
                        objBLDesgloseBE.Estado = "N"
                    End If

                    objBLDesgloseBE.KBld = V_KBld
                    objBLDesgloseBE.BLHijo = V_BLHijo
                    objBLDesgloseBE.Consig = V_Consig
                    objBLDesgloseBE.Conten = V_Conten
                    objBLDesgloseBE.Peso = V_Peso
                    objBLDesgloseBE.Obse = V_Obse
                    objBLDesgloseBE.TOPE = TOPE

                    objBLDesgloseBC = New DesgloseBC

                    If Not V_Estado = "0" Then
                        objBLDesgloseBC.InsertarDesglose(objBLDesgloseBE, bExito, sMensaje)

                    End If


                    i = i + 1

                Loop


            End If

            If bExito Then
                MsgBox("Se ingreso correctamnete el desglose.", True, String.Empty)
                Response.Redirect("Consultar_BillOfLading_Impo.aspx", True)
            Else
                MsgBox("Hubo problemas al ingresar el desglose.", True, String.Empty)
            End If

        
            CalcularCantHijos()

        Catch ex As Exception
            ex.Message.ToString()
        End Try


    End Sub


    Public Sub Modificar()

        Try
            Nuevo()
        Catch ex As Exception
            ex.Message.ToString()
        End Try
    End Sub

    Protected Sub btnSalir_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSalir.Click
        Response.Redirect("Consultar_BillOfLading_Impo.aspx")
    End Sub
End Class